<?php 
// wymagane w layout
echo $this->Section->main();
?>

<?php 
$this->Html->styleBlock("
	div.gallery a.highslide { display: block; width: 186px; height: 186px; padding: 5px; margin: 3px;  border: solid 2px #eee; background-position: center; background-repeat: no-repeat; float: left; overflow: hidden;}
	div.gallery a.highslide:hover { padding: 5px; margin: 3px;  }
",array('inline'=>false));
?>

<div class="content">
	<div id="left-column">
		<?php echo $this->element('left_column')?>		
	</div>
	
	<div class="right-store-column search-bg">
		<?php echo $this->element('search_more',array('plugin'=>'store'))?>
	</div>
	
	<div class="right-store-column">
		<div  class="storeProducts">
		<h2><?php __d("store","Shopping Basket")?></h2>	
		
		<?php

		if(isset($items) && is_array($items)){?>	
			<?php echo $this->Form->create('StoreProduct',array('url'=>array('plugin'=>'store','controller'=>'carts','action'=>'cart_view')));?>			
			<table class="index">
				<tr>
					<th colspan="2">
						<?php echo __d('store','Name',true)?>
					</th>
					<th colspan="2" align="left">
						<?php echo __d('store','Quantity',true)?>
					</th>
					<th>
						<?php echo __d('store','Price',true)?>
					</th>
					<th>
						<?php echo __d('store','Total',true)?>
					</th>
					<th class="last">
						&nbsp;
					</th>					
				</tr>
				<?php
				
				$i=0;
				$sum = 0.00;
				$ilosc_typow = 0;
				$style_class = null;
				
				foreach ($items as $item):
					$style_class = null;
					if ($i++ % 2 == 0) {
						$style_class = ' class="altrow"';
					}
					$ilosc_typow = $item['StoreProduct']['amount'];
					
				?>
				<tr<?php echo $style_class;?>>
					<td width="5%">
						<?php echo $this->Html->link($fileUpload->image($item['StoreUpload']['name'],array('autoResize'=>true,'width'=>40,'imagePathOnly'=>false))
							, array('plugin'=>'store','controller'=>'products','action' => 'view', $item['StoreProduct']['id']),array('escape'=>false,'title'=>$item['StoreProduct']['name'])); ?>&nbsp;
					</td>
					<td width="20%">
						<?php echo $this->Html->link($item['StoreProduct']['name'], array('plugin'=>'store','controller'=>'products','action' => 'view', $item['StoreProduct']['id']),array('escape'=>false)); ?><br/>
			
					</td>	
					<td valign="middle" width="3%">						
						<?php echo $this->Form->input("StoreProduct.{$item['StoreProduct']['id']}.amount",array('value'=>$item['StoreProduct']['amount'],'after'=>false,'size'=>2,'label'=>false,'style'=>'float: left','onchange'=>'$(this).parents("form").submit();')); ?>
					</td>
					<td  width="27%" valign="middle">	
						<?php 
							if(isset($item['StoreType']) && is_array($item['StoreType'])){
							foreach ($item['StoreType']as $type) {?>
							<table class="index">
								<tr>
									<td>
										<?php echo $type['name'];?>
									</td>
									<td>									
										<?php echo (!empty($type['group'])) ? $type['group'] : '';?>
									</td>
									<td width="15">
										<?php echo $this->Html->link($html->image('firma/actions_16_delete.png',array('title'=>__d("store","Delete",true))), array('plugin'=>'store','controller'=>'carts','action'=>'cart_delete_type', $item['StoreProduct']['id'],$type['id']), array('escape'=>false), sprintf(__d('store','Are you sure you want to delete # %s?', true), $type['name'])); ?>
									</td>
								</tr>	
							</table>
						<?php }}	?>	
					</td>
					<td  width="20%" align="right">
						<?php if($item['StoreProduct']['price_przecena'] > 0 && $item['StoreProduct']['price_promocja'] == 0){?>
								<span class="product-view-price-discount"><?php echo $this->Store->price($item['StoreProduct']['price_detaliczna'],2,'','',$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange']);?></span> 
								<span class="product-view-price"><?php echo $this->Store->price($item['StoreProduct']['price_przecena'],2,null,null,$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange'],null,null,'.')?></span>
						<?php }else if( $item['StoreProduct']['price_promocja'] > 0){?>
								<span class="product-view-price-discount"><?php echo $this->Store->price($item['StoreProduct']['price_detaliczna'],2,'','',$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange']);?></span> 
								<span class="product-view-price"><?php echo $this->Store->price($item['StoreProduct']['price_promocja'],2,null,null,$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange'],null,null,'.')?></span>
						<?php }else{?>
								<span class="product-view-price"><?php echo $this->Store->price($item['StoreProduct']['price_detaliczna'],2,null,null,$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange'],null,null,'.')?></span>
						<?php }?>
					</td>
					<td  width="20%" align="right">
						<?php if($item['StoreProduct']['price_przecena'] > 0 && $item['StoreProduct']['price_promocja'] == 0){?>
								<?php
									$price = str_replace(',', '.', $item['StoreProduct']['price_przecena']) * $ilosc_typow;	
									$price_detal = str_replace(',', '.', $item['StoreProduct']['price_detaliczna'])*$ilosc_typow;								
									$sum += $price;
								?>
								<span class="product-view-price-discount"><?php echo $this->Store->price($price_detal,2,'','',$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange']);?></span> 
								<span class="product-view-price"><?php echo $this->Store->price($price,2,null,null,$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange'])?></span>
								 
						<?php }else if( $item['StoreProduct']['price_promocja'] > 0){?>
								<?php
									$price = str_replace(',', '.', $item['StoreProduct']['price_promocja']) * $ilosc_typow;	
									$price_detal = str_replace(',', '.', $item['StoreProduct']['price_detaliczna'])*$ilosc_typow;								
									$sum += $price;
								?>
								<span class="product-view-price-discount"><?php echo $this->Store->price($price_detal,2,'','',$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange']);?></span> 
								<span class="product-view-price"><?php echo $this->Store->price($price,2,null,null,$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange'])?></span>
		
						<?php }else{?>
								<?php
									$price = str_replace(',', '.', $item['StoreProduct']['price_detaliczna']) * $ilosc_typow;									
									$sum += $price;
								?>
								<span class="product-view-price"><?php echo $this->Store->price($price,2,null,null,$item['StoreProduct']['currency_id'],$item['StoreCurrency']['exchange'])?></span>

						<?php }?>
					</td>
					<td class="actions" width="5%">
						<?php echo $this->Html->link($html->image('firma/actions_16_delete_item.png',array('title'=>__d("store","Delete",true))), array('plugin'=>'store','controller'=>'carts','action'=>'cart_delete', $item['StoreProduct']['id']), array('escape'=>false), sprintf(__d('store','Are you sure you want to delete # %s?', true), $item['StoreProduct']['name'])); ?>
					</td>
				</tr>
			<?php endforeach; ?>
				<tr<?php echo $style_class;?>>
					<td colspan="6" align="right" width="100%" class="actions total-cart">
					
						<?php echo __d("store","Total: ")?><span class="product-view-price"><?php echo $this->Store->price($sum,2,null,null,$this->Session->read('Store.selected_currency'),$this->Session->read('Store.selected_exchange'))?></span>
					</td>
					<td class="actions">
						&nbsp;
					</td>
				</tr>
			</table>
			<?php echo $html->link(__d("store","Continue Shopping",true),array('plugin'=>'store','controller'=>'products','action'=>'display'),array('class'=>'button float-left corners'))?>
			<?php echo $html->link(__d("store","Remove All",true),array('plugin'=>'store','controller'=>'carts','action'=>'cart_clear'),array('class'=>'button float-left corners'),__d('store','Are you sure you want to clear cart?',true))?>
			<input type="image" src="/img/store.moon/buttons_update_basket.png" style="border: none; padding: 0px; margin: 4px;" />
			<?php echo $html->link(__d("store","Proceed to payment",true),array('plugin'=>'store','controller'=>'carts','action'=>'cart_customer'),array('class'=>'button float-left corners'))?>			
			
			<?php echo $this->Form->end()?>
		<?php }else{?>
			<?php echo __d('store','Your Shopping Basket is empty.',true)?>
		<?php }?>
		</div>
		<div class="clr"></div>
	</div>
	<div class="clr"></div>
</div>
<div class="clr"></div>		